/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ServerWindows;

import javax.swing.JOptionPane;

/**
 *
 * @author Mohamad
 */
public class ServerWindow extends javax.swing.JFrame {

    /**
     * Creates new form ServerWindow
     */
    
    public ServerWindow() {
        initComponents();
    }
private void confirmationOnExit() {
    if (JOptionPane.showConfirmDialog(this, "Warnning !!\nExting will close all aopen connections, are you sure you want to exit ?", "Warnning !!", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                this.dispose();
    }
}
private void confirmationOnStop() {
    if (JOptionPane.showConfirmDialog(this, "Warnning !!\nThis will close all aopen connections, are you sure you want to stop the server ?", "Warnning !!", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                //CODE HERE:
            //close all open connections and stop server.
        }  
}
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        onlineUsersLabel = new javax.swing.JLabel();
        offlineUsersLabel = new javax.swing.JLabel();
        onlineUsersTextField = new javax.swing.JTextField();
        offlineUsersTextField = new javax.swing.JTextField();
        statisticsLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        ViewDataJButon = new javax.swing.JButton();
        sendMessageJButton = new javax.swing.JButton();
        startJButon = new javax.swing.JButton();
        StopJButton = new javax.swing.JButton();
        serverJMenuBar = new javax.swing.JMenuBar();
        serverMenu = new javax.swing.JMenu();
        startJMenuItem = new javax.swing.JMenuItem();
        stopJMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        exitJMenuItem = new javax.swing.JMenuItem();
        clientsJMenu = new javax.swing.JMenu();
        sendMessageMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("JMessanger Server");
        setName("JMessanger Server"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                serverWindowClosing(evt);
            }
        });

        onlineUsersLabel.setText("Online users");

        offlineUsersLabel.setText("Offline User");
        offlineUsersLabel.setToolTipText("");

        onlineUsersTextField.setEditable(false);
        onlineUsersTextField.setBackground(new java.awt.Color(255, 255, 255));

        offlineUsersTextField.setEditable(false);
        offlineUsersTextField.setBackground(new java.awt.Color(255, 255, 255));

        statisticsLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        statisticsLabel.setText("Statistics");

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        ViewDataJButon.setText("View Data");

        sendMessageJButton.setText("Send Message");
        sendMessageJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendMessageJButtonActionPerformed(evt);
            }
        });

        startJButon.setText("Start");

        StopJButton.setText("Stop");
        StopJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StopJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(startJButon, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(StopJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 135, Short.MAX_VALUE)
                .addComponent(sendMessageJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ViewDataJButon, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {StopJButton, ViewDataJButon, sendMessageJButton, startJButon});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(22, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startJButon, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(StopJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sendMessageJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ViewDataJButon, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {StopJButton, ViewDataJButon, sendMessageJButton, startJButon});

        serverMenu.setText("Server");

        startJMenuItem.setText("Start");
        serverMenu.add(startJMenuItem);

        stopJMenuItem.setText("Stop");
        stopJMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopJMenuItemActionPerformed(evt);
            }
        });
        serverMenu.add(stopJMenuItem);
        serverMenu.add(jSeparator2);

        exitJMenuItem.setText("Exit");
        exitJMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitJMenuItemActionPerformed(evt);
            }
        });
        serverMenu.add(exitJMenuItem);

        serverJMenuBar.add(serverMenu);

        clientsJMenu.setText("Clients");

        sendMessageMenuItem.setText("Send Message");
        sendMessageMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendMessageMenuItemActionPerformed(evt);
            }
        });
        clientsJMenu.add(sendMessageMenuItem);

        serverJMenuBar.add(clientsJMenu);

        helpMenu.setText("Help");

        aboutMenuItem.setText("About");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        serverJMenuBar.add(helpMenu);

        setJMenuBar(serverJMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(onlineUsersLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                            .addComponent(offlineUsersLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(onlineUsersTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                            .addComponent(offlineUsersTextField)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(statisticsLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(52, 52, 52)
                .addComponent(statisticsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(onlineUsersLabel)
                    .addComponent(onlineUsersTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(offlineUsersLabel)
                    .addComponent(offlineUsersTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(43, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleName("JMessanger Server");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void sendMessageJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendMessageJButtonActionPerformed
        // TODO add your handling code here:
        new MessageWindow().setVisible(true);
    }//GEN-LAST:event_sendMessageJButtonActionPerformed

    private void serverWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_serverWindowClosing
        // TODO add your handling code here:
        confirmationOnExit();
    }//GEN-LAST:event_serverWindowClosing

    private void StopJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopJButtonActionPerformed
        // TODO add your handling code here:
        confirmationOnStop();              
    }//GEN-LAST:event_StopJButtonActionPerformed

    private void exitJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitJMenuItemActionPerformed
        // TODO add your handling code here:
        confirmationOnExit();
    }//GEN-LAST:event_exitJMenuItemActionPerformed

    private void sendMessageMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendMessageMenuItemActionPerformed
        // TODO add your handling code here:
        new MessageWindow().setVisible(true);
    }//GEN-LAST:event_sendMessageMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(this,"JMessanger Server V0.1 Alpha","About",JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void stopJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopJMenuItemActionPerformed
        // TODO add your handling code here:
        confirmationOnStop();
    }//GEN-LAST:event_stopJMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ServerWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ServerWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ServerWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ServerWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ServerWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton StopJButton;
    private javax.swing.JButton ViewDataJButon;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenu clientsJMenu;
    private javax.swing.JMenuItem exitJMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JLabel offlineUsersLabel;
    private javax.swing.JTextField offlineUsersTextField;
    private javax.swing.JLabel onlineUsersLabel;
    private javax.swing.JTextField onlineUsersTextField;
    private javax.swing.JButton sendMessageJButton;
    private javax.swing.JMenuItem sendMessageMenuItem;
    private javax.swing.JMenuBar serverJMenuBar;
    private javax.swing.JMenu serverMenu;
    private javax.swing.JButton startJButon;
    private javax.swing.JMenuItem startJMenuItem;
    private javax.swing.JLabel statisticsLabel;
    private javax.swing.JMenuItem stopJMenuItem;
    // End of variables declaration//GEN-END:variables
}
